using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using usm.SolDev.DataBase.DataObjects;

namespace usm.SolDev.UI.User
{
    /// <summary>
    ///     Group name management   
    /// </summary>
    public partial class CreateGroup : usm.SolDev.UI.BaseForm
    {
        #region Private 
        private GroupDataObject groupData;
        #endregion

        #region Constructors
        /// <summary>
        ///     Default constructor
        /// </summary>
        public CreateGroup()
        {
            InitializeComponent();
        }

        /// <summary>
        ///     Initialization constructor
        /// </summary>
        /// <param name="groupData"></param>
        public CreateGroup(GroupDataObject groupData)
        {
            InitializeComponent();

            this.groupData = groupData;

            switch (this.groupData.State)
            {
                case usm.SolDev.Common.Config.ObjectState.New:
                    Text = "New group";
                    break;

                case usm.SolDev.Common.Config.ObjectState.Deleted:
                    Text = "Delete group";
                    break;

                case usm.SolDev.Common.Config.ObjectState.Modified:
                    Text = "Edit group";
                    break;

                case usm.SolDev.Common.Config.ObjectState.Original:
                    Text = "Group";
                    tbName.ReadOnly = true;
                    tbName.Enabled = false;
                    break;

            }

            tbName.Text = this.groupData.Name;
            
        }
        #endregion

        #region Public properties
        /// <summary>
        ///     Group name
        /// </summary>
        public string GroupName
        {
            get { return tbName.Text;}
        }

        /// <summary>
        ///     Group descriptor
        /// </summary>
        public GroupDataObject Group
        {
            get 
            {
                if (groupData == null)
                {
                    groupData = new GroupDataObject(0, tbName.Text);
                    groupData.State = usm.SolDev.Common.Config.ObjectState.New;
                }
                else
                {
                    groupData.Name = tbName.Text;
                }
                
                return groupData;
            }
        }
        #endregion
    }
}


